<?php
class CreateRole extends CakeMigration {

/**
 * Migration description
 *
 * @var string
 * @access public
 */
	public $description = '';

/**
 * Actions to be performed
 *
 * @var array $migration
 * @access public
 */
	public $migration = array(
		'up' => array(
			'create_table' => array(
					'roles' => array(
						  'id' => array(
						      'type'    =>'integer',
						      'null'    => false,
						      'default' => NULL),
						  'name' => array(
						      'type'    =>'string',
						      'null'    => false,
						      'default' => NULL),
						  'indexes' => array(
						      'PRIMARY' => array(
						          'column' => 'id',
						          'unique' => 1)
						  )
					)
				)
		),
		'down' => array(
			'drop_table' => array('roles')
		),
	);

/**
 * Before migration callback
 *
 * @param string $direction, up or down direction of migration process
 * @return boolean Should process continue
 * @access public
 */
	public function before($direction) {
		return true;
	}

/**
 * After migration callback
 *
 * @param string $direction, up or down direction of migration process
 * @return boolean Should process continue
 * @access public
 */
	public function after($direction) {
		$Role = ClassRegistry::init('Role');
    if ($direction == 'up') { //add 2 records to statues table
        $data[0]['id'] = '1';
        $data[0]['name'] = 'Admin';
        $data[1]['id'] = '2';
        $data[1]['name'] = 'Manager';
        $Role->create();
        if ($Role->saveAll($data)){
            echo "Roles table has been initialized";
        }
    } else if ($direction == 'down') {
        //do more work here
    }
		return true;
	}
}
